from django.http import JsonResponse
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.generics import ListCreateAPIView
from rest_framework.pagination import PageNumberPagination

from common.models import GameInfo
from list.serializers import GamgInfoSerializer


class MyPageNumberPagination(PageNumberPagination):
    page_size = 9
    page_query_param = "page"
    page_size_query_param = "size"


# 返回game数据
class GameInfos(ListCreateAPIView):
    queryset = GameInfo.objects.all()
    serializer_class = GamgInfoSerializer

    def get(self, request, *args, **kwargs):
        query_set = GameInfo.objects.all()
        pager = MyPageNumberPagination()
        paged_query_set = pager.paginate_queryset(
            queryset=query_set, request=request, view=self)
        return pager.get_paginated_response(
            GamgInfoSerializer(paged_query_set, many=True).data)
        # serializer = GamgInfoSerializer(paged_query_set, many=True)
        # return JsonResponse(serializer.data, safe=False)


@api_view(['GET'])
def games(resquet):
    return render(resquet, 'web/gallery.html',{})













